<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<style>
    #root{
        width: 200px;
        height: 200px;
        border: 1px solid bisque;
    }
</style>
<script type="text/javascript" src="http://html2canvas.hertzen.com/dist/html2canvas.min.js"></script>
<body>
    <div id="root">
        <h1>aaa</h1>
        <input  type="button" onclick="ok()" value="下载" /> 
    </div>
    <script type="text/javascript">
        function ok() {
            const node = document.getElementById("root")
            html2canvas(node, {
                useCORS: true,
                height: node.offsetHeight,
                width: node.offsetWidth,
                scrollY: 0,
                scrollX: 0
            }).then(async (canvas) => {
                let oImg = new Image();
                oImg.src = canvas.toDataURL();  // 导出图片
                let a=document.createElement("a");
                a.href=oImg.src;
                a.download="image/jpeg";
                a.click();
            })
        }
    </script>
</body>

</html>